package cn.edu.scujcc.customofsichuan;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;


public class SecondPager_Mine_setting extends AppCompatActivity implements View.OnClickListener {

    Intent intent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_secondpager_mine_setting);

        Toolbar toolbar=findViewById(R.id.setting);
        //设置返回键
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        TextView account = findViewById(R.id.setting_account);
        TextView exchange_account = findViewById(R.id.exchange_account);
        TextView logout = findViewById(R.id.logout);


        account.setOnClickListener(this);
        exchange_account.setOnClickListener(this);
        logout.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.setting_account:
                intent=new Intent(this, ThridPager_setting_account.class);
                startActivity(intent);
                break;
            case R.id.exchange_account:
                intent=new Intent(this,exchange_account.class);
                startActivity(intent);
                break;
            case R.id.logout:
                AlertDialog.Builder builder=new AlertDialog.Builder(this);
                View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_logout, null);
                builder.setView(inflate);
                AlertDialog alertDialog = builder.create();
                alertDialog.show();
                Window window=alertDialog.getWindow();
                //设置自定义背景
                window.setBackgroundDrawableResource(R.drawable.share_background);
                //设置动画
                window.setWindowAnimations(androidx.appcompat.R.style.Animation_AppCompat_DropDownUp);
                //获取布局参数
                WindowManager.LayoutParams wlp = window.getAttributes();
                wlp.gravity= Gravity.BOTTOM;
                //使对话框的宽度撑满屏幕
                WindowManager windowManager= (WindowManager) getSystemService(Context.WINDOW_SERVICE);
                wlp.width =windowManager.getDefaultDisplay().getWidth();
                window.setAttributes(wlp);
                //确定退出
                inflate.findViewById(R.id.logout_sure).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //跳转到登录界面
                        intent=new Intent(v.getContext(),login.class);
                        //点击退出后就不可通过返回按钮返回上一个Activity，必须设置以下两个FLAG否则不可生效
                        intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TASK|intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                        alertDialog.cancel();
                    }
                });
                //取消
                inflate.findViewById(R.id.logout_cancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        alertDialog.cancel();
                    }
                });

                break;

        }
    }
}